package com.giscloud.commons.exception;

import com.giscloud.commons.model.Result;

public class BusinessException extends RuntimeException {

    private static final long serialVersionUID = 1144969267587138347L;

    public BusinessException(Integer code, String message, Exception cause) {
        super(code + ":" + message, cause);
    }

    public BusinessException(Integer code, String message) {
        super(code + ":" + message);
    }

    public BusinessException() {
        super();
    }

    public BusinessException(String message, Throwable cause) {
        super(message, cause);
    }

    public BusinessException(String message) {
        super(message);
    }

    public BusinessException(Throwable cause) {
        super(cause);
    }


    public static void throwMessage(String errCode) {
        throw new BusinessException(errCode);
    }

    /**
     * <pre>
     * 抛出业务逻辑异常信息
     * </pre>
     */
    public static void throwMessageWithCode(Integer errCode, String message) {
        throw new BusinessException(errCode, message);
    }

    /**
     * <pre>
     * 抛出业务逻辑异常信息
     * </pre>
     */
    public static void throwResult(Result result) {
        Integer errCode = result.getCode();
        String message = result.getMsg();
        throw new BusinessException(errCode, message);
    }
}
